package com.zb.controller;


import com.zb.dto.SeckillDto;
import com.zb.entity.TbSeckillGoodsModel;
import com.zb.service.TbSeckillGoodsService;

import com.zb.util.DateUtil;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.ParseException;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @ClassName TbSeckillGoodsController
 * @Description 控制器
 * @Author zj
 * @Date 2022/11/16 09:31
 **/
@RestController
@RequestMapping("/tb-seckill-goods-model")
public class TbSeckillGoodsController {
    @Autowired
    public TbSeckillGoodsService tbSeckillGoodsModelService;

    @GetMapping("/list/{time}")
    public List<SeckillDto> list(@PathVariable("time") String time) {
        return tbSeckillGoodsModelService.list(time).stream().map(item -> {
            SeckillDto seckillDto = new SeckillDto();
            BeanUtils.copyProperties(item, seckillDto);
            return seckillDto;
        }).collect(Collectors.toList());
    }

    @GetMapping("/get/{time}/{id}")
    public SeckillDto get(@PathVariable String time, @PathVariable String id) {
        TbSeckillGoodsModel goodsModel = tbSeckillGoodsModelService.get(time, id);
        SeckillDto seckillDto = new SeckillDto();
        BeanUtils.copyProperties(goodsModel, seckillDto);
        return seckillDto;
    }


    @GetMapping("/datemenu")
    public List<String> getDateMenu() {
        return DateUtil.getDateMenus().stream().map(item -> {
            try {
                String format = DateUtil.format(item, "yyyyMMddHHmm");
                return format;
            } catch (ParseException e) {
                e.printStackTrace();
            }
            return null;
        }).collect(Collectors.toList());
    }
}
